<?php
if($_REQUEST['_a'] == "del") {
	$sql = "delete from map_ads where id='".$_REQUEST['_d']."'";
	mysql_query($sql) or die(mysql_error());
	echo '<script>location.href="index.php?tc=map_ads";</script>';

}
?>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
  $('a[rel*=facebox]').facebox()
}) 
</script>
<form name="nnf" method="post" action="#">
<table border="0" width="100%" align="center">
<tr>
	<td width="46%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">
    Map Top Ads</span>&nbsp; 
	<!--<input type="button" name="addnew" value="Add New" onclick="return show();" />-->
	</td>
	<td width="40%" align="right" class="font12">
    <a href="index.php?tc=add_ads" class="font12">Add Mapping</a>
    </td> 
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>    
</table>
<table width="100%" align="center" border="0" class="list">
<thead>
<tr>
	<td align="center" width="30">#</td>
	<td align="center" width="200">Page Name</td>
    <td align="center" width="200">Ads Name</td>

    <td align="center" width="100">Status</td>
    <td align="center">Action</td>
</tr>
</thead>
<?php
include('includes/function.php');
$self="index.php?tc=job_category&_st=".$_REQUEST['_st'];
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;

	$res = mysql_query("select id from page");
	
	$query = mysql_query("select b.`id`, a.`page_name`, c.`ad_name`, b.`active_status`,upload_file, c.id file_id 
						 from page a inner join map_ads b on(b.page_name = a.id and a.active_status = '1') 
						 inner join banner_ads c on (b.ad_name = c.id and c.active_status = '1') 
						 where banner_type = 'top'
						 order by b.id desc limit $offset , $rowsPerPage") or die(mysql_error());

$i=1;
while($q = mysql_fetch_array($query))
{ 

	if($q["active_status"] == 1) $status = "Activated";
	else $status = "Deactivated";
	?>
    <tr class="font12">
        <td align="center"><?php echo $i+$offset;?></td>
        <td align="left" width="250px;"><?php echo $q["page_name"];?></td>
        <td align="left" width="300px;"><?php echo $q["ad_name"];?></td>
        
        <td align="center"><?php echo $status;?></td>
        <td align="center"><a href="index.php?tc=add_ads&_d=<?php echo $q['id'];?>" class="font12">Edit</a> | 
        	<a href="index.php?tc=map_ads&_d=<?php echo $q['id'];?>&_a=del&page=<?php echo $pageNum;?>" onclick="return confirm('Are you sure want to delete?')" class="font12">Delete</a>
        </td>
   	</tr>     
<?php 
	$i++;
}
?>
<?php 
if(mysql_num_rows($res) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="7" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table>
</form>